home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #21 (Jun 87) / basic source / TE DEMO2 (.txt) next >
AmigaBASIC Source Code  |  1987-05-08  |  3KB  |  112 lines

  1. 'Text Edit Demo
  2. 'By Dave Kelly
  3. 'teRec Wrap by Dave Smith
  4. '©MacTutor 1987
  5.  
  6. OriginalEditString$="This is the first string."
  7. endofstring=LEN(OriginalEditString$)
  8. ' Set up rectangle for TEUPDATE call
  9. rect%(0)=20:rect%(1)=10:rect%(2)=200:rect%(3)=460
  10.  
  11. WINDOW 1,"Text Edit Demo",(15,40)-(495,330),2
  12. EDIT FIELD 1,OriginalEditString$,(10,20)-(460,200),6,1
  13. PRINT "Click mouse button outside of edit field or type …"
  14. LOCATE 15,1
  15. PRINT "The Text Edit field has been created. (EDIT FIELD statement)"
  16. LOCATE 17,1:PRINT "TextEdit Buffer:"
  17. oldkey$=""
  18. GOSUB wrap: REM make textedit wrap to view rectangle
  19. <0x00,0x07> endofstring+1,endofstring+1,WINDOW(6)
  20. GOSUB eventloop
  21.  
  22. 'Set the edit field text to a new string
  23. NewEditString$="This the second string. (replaced old string)"
  24. <0x00,0x07> SADD(NewEditString$),LEN(NewEditString$),WINDOW(6)
  25.  
  26. 'Re-draw the edit field (needs to be re-drawn after setting new text)…
  27. <0x00,0x07> VARPTR(rect%(0))
  28. <0x00,0x07> VARPTR(rect%(0)),WINDOW(6)
  29. LOCATE 15,1
  30. PRINT "The Text Edit field has been set to a new string (TESETTEXT call)."
  31. GOSUB eventloop
  32.  
  33. 'Set the selection range…
  34. <0x00,0x07> 1,6,WINDOW(6)
  35. LOCATE 15,1
  36. PRINT "The text has been selected… selection range";STRING$(50," ")
  37. PRINT "is from before character 1 until before character 6. (TESETSELECT call)"
  38. GOSUB eventloop
  39.  
  40. 'Delete the selected text…
  41. <0x00,0x07> WINDOW(6)
  42. LOCATE 15,1
  43. PRINT "The selected text has been deleted. (TEDELETE call)";STRING$(30," ")
  44. PRINT STRING$(150," ")
  45. GOSUB eventloop
  46.  
  47. 'De-activate the edit field…
  48. <0x00,0x07> WINDOW(6)
  49. LOCATE 15,1
  50. PRINT "The text has been deactivated (TEDEACTIVATE call)"
  51. GOSUB eventloop
  52.  
  53. 'Re-activate the edit field...
  54. <0x00,0x07> WINDOW(6)
  55. LOCATE 15,1
  56. PRINT "The text has been activated (TEACTIVATE call)";STRING$(10," ")
  57. GOSUB eventloop
  58.  
  59. 'Insert new text at the insertion point…
  60. TextToInsert$="-This text was inserted-"
  61. <0x00,0x07> SADD(TextToInsert$),LEN(TextToInsert$),WINDOW(6)
  62. LOCATE 15,1
  63. PRINT "Text has been inserted at the insertion point. (TEINSERT call)";STRING$(20," ")
  64. GOSUB eventloop
  65.  
  66. quit:
  67. EDIT FIELD CLOSE 1
  68. CLS: END
  69.  
  70. eventloop:
  71. WHILE MOUSE(0)<>1
  72. GOSUB TextEdit
  73. key$=EDIT$(1)
  74. IF key$<>oldkey$ THEN GOSUB processtext
  75. oldkey$=key$
  76. WEND
  77. RETURN
  78.  
  79. processtext:
  80. chartyped$=RIGHT$(key$,1) :REM how do you get last char typed?
  81. LOCATE 17,18
  82. PRINT SPACE$(4);
  83. LOCATE 17,18
  84. IF chartyped$<>CHR$(13) THEN PRINT chartyped$ :ELSE PRINT "CR"
  85. RETURN
  86.  
  87. TextEdit:
  88. myHandle#=WINDOW(6)
  89. LOCATE 17,24:PRINT myHandle#
  90. ptr1=PEEK(myHandle#+3)
  91. ptr2=PEEK(myHandle#+2)
  92. ptr3=PEEK(myHandle#+1)
  93. ptr4=PEEK(myHandle#+0)
  94. ptr#=(ptr3*(65536)) + (ptr2*256) + ptr1
  95. telength1 = PEEK(ptr#+61)
  96. teLength2=PEEK(ptr#+60)
  97. teLength = teLength2*256+telength1
  98. LOCATE 17,35:PRINT ptr#
  99. LOCATE 17,45:PRINT teLength
  100. RETURN
  101.  
  102. wrap:
  103. GOSUB TextEdit : REM get teRec address
  104. REM poke new values in teRec
  105. crOnlyAdd#=ptr#+72
  106. cronly%=0:POKE crOnlyAdd#,0 :REM turn OFF cronly
  107. FOR i=0 TO 7
  108. POKE ptr#+8+i,PEEK(ptr#+i): REM dest rect = view rect
  109. NEXT i
  110. <0x00,0x07> WINDOW(6): REM re-do line endings
  111. RETURN
  112.